package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqClassModeResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class SetNoDistrubTimeReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        /* 有以下两种情况
       1、*WT,imei,V4,CLASS,HHMMSS,sequence,content,HHMMSS,A/V,lat,N/S,lgt,E/W,speed,orientation,YYMMDD,FFFFFFFF#
       2、*WT,800115470000876,V4,CLASS,111054#
         实际： *WT,866248050395985,V4,CLASS,123831,1,0400080011213141516070,173914,A,2250.2255,N,11391.6023,E,0.31,0,020621,FFFFDFFF*/
        //将指令末尾的#截取掉
        String str = data.substring(0, data.length() - 1);
        //分割字符串获取指令信息
        String[] split = data.split(",");
        String commandNumber = split[4];    // 指令序列号
        String imei = split[1];   // imei号
        String messageType = split[2];
        String type = split[3];
        String sequence = split[5];
        String deviceTime = split[7];
        String value = split[6];
        String lat = split[9];
        String lgt = split[11];
        String speed = split[13];
        String orientation = split[14];
        String date = split[15];
        String deviceStatus = split[16];
        List<Double> list = LocationUtils.transiformLatAndLng(lgt, lat);
        MqClassModeResult mqClassModeResult = new MqClassModeResult();
        mqClassModeResult.setCommandNumber(commandNumber);
        mqClassModeResult.setDeviceDate(date);
        mqClassModeResult.setDeviceStatus(deviceStatus);
        mqClassModeResult.setDeviceTime(deviceTime);
        mqClassModeResult.setImei(imei);
        mqClassModeResult.setSequence(Integer.parseInt(sequence));
        mqClassModeResult.setValue(value);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqClassModeResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().classModeResponse(mqClassModeResult);
        return imei;
    }
}

//        String str = data.substring(0, data.length() - 1); //将指令末尾的#截取掉
//        //分割字符串获取指令信息

//        String imei = split[1];
//        String commandNumber = split[4];
//        String scheduleSeq=split[5];//课程表序号最多为10
//        String setting = split[6];//例如：2200（开始时间） 2300（结束时间） 10203141516171（周几和开关）
//        String startTime=setting.substring(0,4);//开始时间
//        String endTime=setting.substring(4,8);// 结束时间
//        String daySetting=setting.substring(8,setting.length()); //周几的开关设置
//        String onOff=setting.substring(setting.length()-1);
//        String time = split[7];//指令回复的时间（时分秒）
//        String dataValid = split[8];//数据有效位（A/V），A 表示 GPS 数据是有效定位数据，V 表示是无效定位数据
//        String lat = split[9];
//        String latNS = split[10];//北纬还是南纬
//        String lng = split[11];
//        String lngWE = split[12];//西经还是东经
//        String speed = split[13];
//        String orientation = split[14];
//        String date = split[15];//年月日
//        String deviceStatus = split[16];//设备状态
//        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
//        //构建一个存储一般定位信息和一般设备信息的实体类对象
//        MqNormalData mqNormalData = new MqNormalData();
//        mqNormalData.setCommandNumber(commandNumber);
//        mqNormalData.setImei(imei);
//        mqNormalData.setTime(time);
//        mqNormalData.setSpeed(Double.parseDouble(speed));
//        mqNormalData.setLongitude(list.get(0));
//        mqNormalData.setLatitude(list.get(1));
//        mqNormalData.setOrientation(Integer.parseInt(orientation));
//        mqNormalData.setDate(date);
//        mqNormalData.setDeviceStatus(deviceStatus);
//        mqNormalData.setDataValid(dataValid);
//        mqNormalData.setLatNS(latNS);
//        mqNormalData.setLngWE(lngWE);
//        //构建一个存储相关信息的实体类对象
//        MqSetNoDisturbTimeData mqSetNoDistrubTimeData = new MqSetNoDisturbTimeData();
//        mqSetNoDistrubTimeData.setMqNormalData(mqNormalData);
//        mqSetNoDistrubTimeData.setStartTime(startTime);
//        mqSetNoDistrubTimeData.setEndTime(endTime);
//        mqSetNoDistrubTimeData.setDaySetting(daySetting);
//        mqSetNoDistrubTimeData.setScheduleSeq(scheduleSeq);
//        mqSetNoDistrubTimeData.setOnOff(onOff);
//        InjectFeignService.getIrmFeignClientService().setNoDisturbTime(mqSetNoDistrubTimeData);
//        return imei;
